package cn.itcast.es;

import org.apache.http.HttpHost;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;

import java.io.IOException;

public class ES_Doc_Batch {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("192.168.20.129", 9200, "http"))
        );

        // 批量插入数据
//        BulkRequest request = new BulkRequest();
//
//        request.add(new IndexRequest("user").id("1001").source(XContentType.JSON,"name", "张三", "age", 20));
//        request.add(new IndexRequest("user").id("1002").source(XContentType.JSON,"name", "李四", "age", 21));
//        request.add(new IndexRequest("user").id("1003").source(XContentType.JSON,"name", "王五", "age", 22));
//
//        BulkResponse bulk = client.bulk(request, RequestOptions.DEFAULT);
//        System.out.println("批量插入数据:"+bulk.status()+","+bulk.getTook().getMillis()+"ms");




        client.close();
    }
}
